<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>合生元</title>
	<script src=" https://res.wx.qq.com/open/js/jweixin-1.0.0.js?v=${fns:getConfig('drawVersion')}"></script>
<!-- 	<script src="http://sujia.node.c2d.me/wx/api/jsapiConfig?callback=wx.config&amp;debug=true"></script> -->
    <script>
        var phoneWidth = parseInt(window.screen.width);
        var phoneHeight = parseInt(window.screen.height);
        var phoneScale = phoneWidth / 640;
        var ua = navigator.userAgent;
        if (/Android (\d+\.\d+)/.test(ua)) {
            var version = parseFloat(RegExp.$1);
            if (version > 2.3) {
                document.write('<meta name="viewport" content="width=640, initial-scale= ' + phoneScale + ' ,minimum-scale = ' + phoneScale + ', maximum-scale = ' + phoneScale + ', target-densitydpi=device-dpi">');
            }
            else {
                document.write('<meta name="viewport" content="width=640, initial-scale= ' + phoneScale + ' , target-densitydpi=device-dpi">');
            }
        }
        else {
            document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');
        }</script>
        
    <script src="http://cdnjs.gtimg.com/cdnjs/libs/wxmoment/0.0.2/wxmoment.min.js"></script>
    <script src="http://wximg.qq.com/wxp/libs/wxmoment/0.0.4/wxmoment.min.js"></script>
    <script type="text/javascript">
    	$(function(){
/*     	     	    alert('${map.url}');   
    	   	    	alert(location.href.split('#')[0] == '${map.url}');  	
    	   	    	alert(location.href.split('#')[0]);  
    	   	    	alert('${map.appId}');
    	   	    	alert(parseInt('${map.timestamp}'));
    	   	    	alert('${map.nonceStr}');
    	   	    	alert('${map.signature}');    */
    	   	     	wx.config(
    	   	    			{
    	   	    			debug: false,
    	   	    			appId: '${map.appId}',
    	   	    			timestamp: parseInt('${map.timestamp}'),
    	   	    			nonceStr: '${map.nonceStr}',
    	   	    			signature: '${map.signature}',
    	   	    			jsApiList: [
    	   	    			"onMenuShareTimeline",
    	   	    			"onMenuShareAppMessage",
    	   	    			"onMenuShareQQ",
    	   	    			"onMenuShareWeibo",
    	   	    			"onMenuShareQZone",
    	   	    			"startRecord",
    	   	    			"stopRecord",
    	   	    			"onVoiceRecordEnd",
    	   	    			"playVoice",
    	   	    			"pauseVoice",
    	   	    			"stopVoice",
    	   	    			"onVoicePlayEnd",
    	   	    			"uploadVoice",
    	   	    			"downloadVoice",
    	   	    			"chooseImage",
    	   	    			"previewImage",
    	   	    			"uploadImage",
    	   	    			"downloadImage",
    	   	    			"translateVoice",
    	   	    			"getNetworkType",
    	   	    			"openLocation",
    	   	    			"getLocation",
    	   	    			"hideOptionMenu",
    	   	    			"showOptionMenu",
    	   	    			"hideMenuItems",
    	   	    			"showMenuItems",
    	   	    			"hideAllNonBaseMenuItem",
    	   	    			"showAllNonBaseMenuItem",
    	   	    			"closeWindow",
    	   	    			"scanQRCode",
    	   	    			"chooseWXPay",
    	   	    			"openProductSpecificView",
    	   	    			"addCard",
    	   	    			"chooseCard",
    	   	    			"openCard"
    	   	    			]
    	   	    			}
    	   	    			)  	  
    	   	    	
    			        
    			        wx.ready(function(){
    			        			        	
  			          		 wx.onMenuShareTimeline({
  			        			    //title: '分享单号码:${sharecode}', // 分享标题
  			       			    title: '快来抽奖吧！', // 分享标题 
  			        			    link: '${url}', // 分享链接
  			        			    imgUrl: 'http://springdraw.c2d.me/image/分享消息.jpg', // 分享图标
  			        			    success: function () { 
  			        			        // 用户确认分享后执行的回调函数
  			        			    },
  			        			    cancel: function () { 
  			        			        // 用户取消分享后执行的回调函数
  			        			    }
  			        			});	  
  			        		 
  			        		 wx.onMenuShareAppMessage({
  			        			    //title: '分享单号码:${sharecode}', // 分享标题
  			        			    title: '快来抽奖吧！', // 分享标题 
  			        			    desc: '合生元抽奖', // 分享描述
  			        			    link: '${url}', // 分享链接
  			        			    imgUrl: 'http://springdraw.c2d.me/image/分享消息.jpg', // 分享图标
  			        			    type: '', // 分享类型,music、video或link，不填默认为link
  			        			    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
  			        			    success: function () { 
  			        			        // 用户确认分享后执行的回调函数
  			        			    },
  			        			    cancel: function () { 
  			        			        // 用户取消分享后执行的回调函数
  			        			    }
  			        			});   	       		
    			        		 
    			   	    })   
    	   	    
    	   	    });
    	   	        	        
	</script>        
    <link rel="stylesheet" href="assets/css/draw/main2.css"/>
</head>
<body>
<div class="wrap index-bj">
    <div class="index-title">
    <span class="frequency">
 			<c:choose>
			   <c:when test="${drawTimes ==null}">  
				   0
			   </c:when>
			   <c:otherwise> 
		    	  ${drawTimes }
			   </c:otherwise>
			</c:choose>	              
  	</span>
  	</div>

    <i class="arrow"></i>
    <div class="bird-box">
        <a href="javascript:;" class="bird1"></a>
        <a href="javascript:;" class="bird2"></a>
    </div>
    <div class="index-btn-box">
        <a href="${ctxFront}/getMyAwards?openId=${openid}&fromSystem=${fromSystem}" class="index-btn1"></a>
        <a href="${ctxFront}/winner?openid=${openid}&pageindex=1&pagesize=5" class="index-btn2"></a>
    </div>
    <a href="${ctxFront}/rule" class="Activityrule">活动规则</a>
    <div class="ICP"></div>
    <footer></footer>
    <!--中奖弹窗start-->
    <div class="Popup1-box">
        <div class="light"></div>
        <div class="xx-content">
            <i class="small-xx small-xx-left"></i>
            <span class="large-xx"></span>
            <i class="small-xx small-xx-right"></i>
        </div>
        <div class="Frame">
            <a href="javascript:;" class="Frame-clear"></a>
            <span class="winning-title"></span>
            <h2><span class="winning-name">法国机票</span></h2>
            <h3>
                <p id="description">填写领奖信息</p>
                <span class="winning-name2">法国机票带回家</span>
            </h3>
            
            <a href="${root}/front?openId=${openid}&fromSystem=${fromSystem}" class="Frame-btn">填写领奖信息</a>
        </div>
        <a href="javascript:;" class="Popup-bird1"></a>
    </div>
    <!--中奖弹窗end-->
    <!--未中奖弹窗start-->
    <div class="Popup2-box">
        <div class="xx-content2">
            <i class="small-xx2 small-xx-left2"></i>
            <span class="large-xx2"></span>
            <i class="small-xx2 small-xx-right2"></i>
        </div>
        <div class="Frame2">
            <a href="javascript:;" class="Frame-clear"></a>
            <span class="no-winning-title"></span>
            <h3>
                <p>赶快买合生元产品</p>
                <p>再接再厉吧！</p>
            </h3>
            <a href="${root}/front?openId=${openid}&fromSystem=${fromSystem} " class="Frame-btn2">返回</a>
        </div>
        <a href="javascript:;" class="Popup-bird2"></a>
    </div>
    <!--未中奖弹窗 end-->
</div>
<!--js-->
<script src="http://wximg.qq.com/wxp/libs/wxmoment/0.0.4/wxmoment.min.js"></script>
<script>

	/**弹框方法**/
function tip(msg){

	$('.bird1,.bird2,.samll-bird').bind("click",function (o) {
		draw();	
	});				
		
	//弹框
	alert(msg);
	
 			
}
	
	$(function(){

	});
	
function draw(){
	
	$('.bird1,.bird2,.samll-bird').unbind("click");
	
	//异步请求抽奖
	$.ajax({
		url:'${ctxFront}/draw',
		type:'post',
		data:{ openid : "${openid }",fromSystem : "${fromSystem}" },
		dataType:'json',
		success:function(res){    					
			if(!res || !res.error){
				tip('抽奖异常:请求响应格式不正确');
				return;
			}
			
			if(res.error.errCode==1){
				if(res.error.errMsg != null){
/*         						tip('抽奖异常:'+res.error.errMsg); */
					flag = true;
					return;
				}else{
					tip("注册成为合生元会员即有机会抽取千元大奖");
					return;
				}
			}
			
			//抽奖正常
			var awardDto = res.obj;
			if(awardDto){
				if(!awardDto.check){
					tip(awardDto.msg);
					return
				}
				
				if(awardDto.award){
					
					  $(".Popup1-box").show()
					    		
					var awardTypeName = awardDto.awardtypeName;
					    							
					//如果不是实物，就隐藏
/* 					if(awardTypeName != 'commodity' && awardTypeName != 'moviecode'){
						$(".Frame-btn").hide();
					} */
					
						//奖品名称
					var name =$("#awardname");
						
					//修改奖品信息
					$(".winning-name").html(awardDto.awardName);	
					
					//提示信息
					var tipsHtml = null;   							
					if(awardTypeName  ==  'coupon' || awardTypeName  ==  'points'){
						tipsHtml = "详情请到合生元账户中查看";
						$(".winning-name2").hide();						
		                $('.Frame-btn').html('确定');							
					}		
					else if(awardTypeName  ==  'exchange'){
						tipsHtml = "请凭提货券到附近门店领取奖品";
						$(".winning-name2").hide();						
		                $('.Frame-btn').html('确定');						
					}							
					else if(awardTypeName  ==  'moviecode'){
						tipsHtml = "马上分享给好友领取另一张电影票！";
						$(".winning-name2").hide();
						
		                //跳到分享页面
		                $('.Frame-btn').html('点击分享给好友');
				        $('.Frame-btn').attr('href','${ctxFront}/shareIndex?shareId='+awardDto.shareId+"&openId=${openid}"
				        		+"&fromSystem=${fromSystem}"); 						
					}	
					else if(awardTypeName  ==  'commodity'){
						$(".winning-name2").html("把"+awardDto.awardName+"带回家");	
						tipsHtml = "填写领奖信息"
						
				        //修改收件人信息链接
				        $('.Frame-btn').attr('href','${ctxFront}/contactInformation?awardname='+awardDto.awardName+"&winnerid="
				        			+awardDto.winnerid+"&openid=${openid }"+"&fromSystem=${fromSystem}"); 						
					}
					$("#description").html(tipsHtml);	
					   		            	           
				}else{
				    $(".Popup2-box").show()
				}
			}else{
				tip('抽奖异常:抽奖返回数据错误');
				return;
			}
			
			var str =$(".frequency");
			$(".frequency").html(awardDto.remain);
		},
		error:function(res){
			if(res.responseText != null){
				//tip('抽奖异常:'+res.responseText);
				tip("网络加载延迟,请再试!");
				return;
			}else{
				tip("网络加载延迟,请再试!");
				return;
			}    					  					
		}
		
	})      		
}
	
$(".bird1,.bird2,.samll-bird").on("click", function (o) {
		draw();	
}),
$(".Frame-clear").on("touchstart", function (o) {
    $(".Popup1-box,.Popup2-box").hide()
   		$('.bird1,.bird2,.samll-bird').bind("click",function (o) {
			draw();		
		});
});
</script>
</body>
</html>